#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "tcpmgr.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , _chat_dlg(nullptr)
    , _forget_dlg(nullptr)
    , _login_dlg(nullptr)
    , _regist_dlg(nullptr)
{
    ui->setupUi(this);
    _login_dlg = new LoginDialog(this);
    _login_dlg->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
    setCentralWidget(_login_dlg);
    _login_dlg->show();
    connect(_login_dlg, &LoginDialog::sigSwitchRegister, this, &MainWindow::SwitchRegister);
    connect(_login_dlg, &LoginDialog::sigSwitchForget, this, &MainWindow::SwitchForget);
    connect(TcpMgr::GetInstance().get(), &TcpMgr::sig_switch_chatdlg, this, &MainWindow::SwitchChat);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::SwitchRegister()
{
    _regist_dlg = new RegisterDialog(this);
    connect(_regist_dlg, &RegisterDialog::sigSwitchLogin, this, &MainWindow::SwitchLogin);
    _regist_dlg->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
    setCentralWidget(_regist_dlg);
    _regist_dlg->show();
}

void MainWindow::SwitchLogin()
{
    _login_dlg = new LoginDialog(this);
    connect(_login_dlg, &LoginDialog::sigSwitchRegister, this, &MainWindow::SwitchRegister);
    connect(_login_dlg, &LoginDialog::sigSwitchForget, this, &MainWindow::SwitchForget);
    _login_dlg->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
    setCentralWidget(_login_dlg);
    _login_dlg->show();
}

void MainWindow::SwitchForget()
{
    _forget_dlg = new ForgetDialog(this);
    connect(_forget_dlg, &ForgetDialog::sigSwitchLogin, this, &MainWindow::SwitchLogin);
    _forget_dlg->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
    _forget_dlg->show();
    setCentralWidget(_forget_dlg);
}

void MainWindow::SwitchChat()
{
    _chat_dlg = new ChatDialog(this);
    _chat_dlg->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
    setCentralWidget(_chat_dlg);
    _chat_dlg->show();
    _chat_dlg->setMinimumSize(QSize(850, 600));
    _chat_dlg->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}
